package com.naiterui.ehp.bs.doctor.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.support.utils.JsonMapper;
import com.naiterui.ehp.bs.doctor.service.IDoctorSyncService;
import com.naiterui.ehp.bs.doctor.vo.requestparam.DoctorParam;
import com.naiterui.ehp.bs.patient.controller.ApPatientController;
import com.naiterui.ehp.bs.patient.exception.ExceptionCodes;
import com.naiterui.ehp.bs.patient.utils.exception.PatientBusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = SwaggerTag.BADACHU + SwaggerTag.USER_INFO)
@RequestMapping("ap/doctorSync")
@Controller
public class AdDoctorSyncController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ApPatientController.class);

    @Autowired
    private IDoctorSyncService doctorSyncService;

    // 添加医生信息
    @ResponseBody
    @RequestMapping(value = "saveDoctor", method = RequestMethod.POST)
    @ApiOperation(value = "添加医生信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "headUrl", value = "头像", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "姓名", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "hospitalName", value = "医院名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "customDepartment", value = "科室名称", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "titleId", value = "职称 0医师，1副主任医师，2主任医师，3主治医师，4主院医师", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "recommCode", value = "邀请码", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "expertise", value = "医生擅长", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "introduction", value = "医生介绍", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "platform", value = "用户平台  10：八大处", required = true, dataType = "int", paramType = "query")})
    public ResponseVO<DoctorParam> saveDoctor(DoctorParam doctorParam) throws Exception {
        LOGGER.info("doctor save info, data {}", JsonMapper.toJson(doctorParam));
        if(doctorParam.getDoctorId() == null || StringUtils.isEmpty(doctorParam.getName()) || doctorParam.getPlatform() == null){
            LOGGER.error("doctor base ERROR ; illegal param : doctor is null");
            throw new PatientBusinessException(ExceptionCodes.PARAM_ERROR);
        }
        doctorSyncService.saveDoctor(doctorParam);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, doctorParam);
    }
}
